/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ita.controller;

import br.ita.model.dao.DAO;
import br.ita.model.dao.GenericDAO;
import br.ita.model.dao.HibernateUtil;
import br.ita.model.dao.LoginDAO;
import br.ita.model.dao.StoreDAO;
import br.ita.model.entities.Login;
import br.ita.model.entities.LojaEspecialista;
import integration.BuscaPe.Buscape;
import integration.BuscaPe.BuscapeUrlJson;
import integration.BuscaPe.ConnectUrlJson;
import integration.BuscaPe.ProductEntityJson;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "store", urlPatterns = {"/store"})
public class StoreController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        
        String profileId = request.getParameter("profileid");
        String lojaNome = request.getParameter("lojaNome");
        String lojaUrl = request.getParameter("lojaUrl");
        //String lojaProducts = request.getParameter("lojaProdutos");
        
        LojaEspecialista loja = new LojaEspecialista();
        loja.setLojaNome(lojaNome);
        loja.setLojaVendedorId(Integer.parseInt(profileId));
        loja.setLojaUrl(lojaUrl);

        Buscape p = new Buscape(new ConnectUrlJson());
        ArrayList<ProductEntityJson> pr = (ArrayList<ProductEntityJson>) p.retrieveProductByKeyword("celular");
        loja.setLojaProducts(pr.toString());
        
        DAO banco = new StoreDAO();
        banco.insert(loja);        
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
    }
}
